Skip to content

Expose the information in the ImageData type. #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 17, 2015

Conversation

asolove
Copy link
Contributor

@asolove asolove commented Dec 17, 2015

  • Getting width and height of an ImageData are not effecting.
  • The pixel information is availalbe as a Uint8ClampedArray.

This is my first contribution to a purescript module in public use, so let me know if I've done something wrong. In particular, I've removed some signatures that could be backwards-compatibly implemented, but would perhaps be confusing in the future. I don't know how this community thinks about changing contracts in releases so I am happy to put them back.

- Getting width and height of an ImageData are not effecting.
- The pixel information is availalbe as a Uint8ClampedArray.

-- | An array of pixel data.
foreign import data CanvasPixelArray :: *
type ImageData = { width :: Number, height :: Number, data :: Uint8ClampedArray }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Number be Int here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much nicer than a foreign type 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't worked with the FFI before. The underlying value the canvas gives us will be a Number with an integral value. If I can just declare it as Int here and that works, that's great. If I need to explicitly call fromNumber on it inside the js function I'm happy to do that too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs say height is "an unsigned long representing the actual height" for example. I think we can use Int here.

The reason for the current code is that Number was the only option back when this was added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the underlying representation of Int still just a Number? I'm not sure whether I can just declare the type here and it works or if I need to actually coerce the Number to an Int.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it's just a number. They're syntactically forced to be actual ints in the compiler, and the operators are modified to preserve integerness.

@paf31
Copy link
Contributor

paf31 commented Dec 17, 2015

Looks nice! I'm happy to make a major version release since the type changes make things much simpler IMO.

@asolove
Copy link
Contributor Author

asolove commented Dec 17, 2015

Alright, updated those to Int. Let me know if there's other things worth changing. I've got this working locally on a little experiment and having some fun.

@@ -23,6 +23,7 @@
"purescript-eff": "^0.1.0",
"purescript-functions": "^0.1.0",
"purescript-maybe": "^0.3.0",
"purescript-exceptions": "^0.3.1"
"purescript-exceptions": "^0.3.1",
"purescript-arraybugger-types": "^0.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arraybuffer-types 😄

This is what I get for testing my changes by copy/pasting into an existing bower_modules/ folder. Sorry
@asolove
Copy link
Contributor Author

asolove commented Dec 17, 2015

Ugh. So, learning opportunity: what is the right way to actually try the local changes in a library like this that isn't runnable itself? I was literally copy/pasting changes into another instance of purescript-canvas inside the bower-modules of a project I was building. But that obviously doesn't cover problems like this.

@paf31
Copy link
Contributor

paf31 commented Dec 17, 2015

We can add a .travis.yml file to have Travis test the build from scratch. For now, I would just try removing the bower_components and output directories and running bower update && pulp build.

@asolove
Copy link
Contributor Author

asolove commented Dec 17, 2015

Ok I can confirm that was failing before the spelling change and passes
now. Thanks!

On Wed, Dec 16, 2015 at 9:26 PM, Phil Freeman [email protected]
wrote:

We can add a .travis.yml file to have Travis test the build from scratch.
For now, I would just try removing the bower_components and output
directories and running bower update && pulp build.


Reply to this email directly or view it on GitHub
#28 (comment)
.

paf31 added a commit that referenced this pull request Dec 17, 2015
Expose the information in the ImageData type.
@paf31 paf31 merged commit e1da5d9 into purescript-web:master Dec 17, 2015
@paf31
Copy link
Contributor

paf31 commented Dec 17, 2015

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants